﻿Public Class AutoInc
    Public Shared Function AutoIncStr(ByVal dt As DataTable, ByVal ColumnName As String, byval prefix As String) As String
       If dt.Rows.Count = 0 Then
            Return prefix + "00000"
        End If
        Dim row As DataRow = dt.Rows(dt.Rows.Count - 1)
        ' lay vi tri cuoi cung
        Dim s_Ma As String = row(ColumnName).ToString()
        Dim i_ma As Integer = Convert.ToInt32(s_Ma.Replace(prefix, "")) + 1
        Dim zero As String = ""
        If i_ma < 10 Then
            zero = "0000"
        ElseIf i_ma < 100 Then
            zero = "000"
        ElseIf i_ma < 1000 Then
            zero = "00"
        ElseIf i_ma < 10000 Then
            zero = "0"
        End If
        s_Ma = prefix & zero & i_ma
        Return s_Ma
    End Function

    Public Shared Function AutoIncInt(ByVal dt As DataTable, ByVal ColumnName As String) As String
        If dt.Rows.Count = 0 Then
            Return 0
        End If
        ' lay vi tri cuoi cung
        Dim row As DataRow = dt.Rows(dt.Rows.Count - 1)
        Dim ma As Integer = Convert.ToInt32(row(ColumnName)) + 1
        Return ma
    End Function
End Class
